package org.xvergabe.forms.poc.pdfgenerator;

import org.xvergabe.forms.poc.helper.Labeller;
import org.xvergabe.xsd.forms.components.x20.Address;
import org.xvergabe.xsd.forms.components.x20.Contact;
import org.xvergabe.xsd.forms.components.x20.Organization;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;

/**
 * Class to write a Organization Component to a PDF
 * 
 * @author schiller
 *
 */
public class OrganizationPdfWriter implements XmlPdfWriter<Organization> {

	@Override
	public void writePdfFromXml(Organization organization, PdfWriter writer, Document document) {

		AddressPdfWriter addressPdfWriter = new AddressPdfWriter();
		ContactPdfWriter contactPdfWriter = new ContactPdfWriter(); 
		
		Address address = organization.getAddress();
		Contact contactdata = organization.getContactDataArray(0);
		
		try {
			document.add(Labeller.getLabelParagraphFor(organization));
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
		if(!(address==null)){
			addressPdfWriter.writePdfFromXml(address, writer, document);
		}
		
		if(!(contactdata==null)){
			contactPdfWriter.writePdfFromXml(contactdata, writer, document);
		}

	}

}
